﻿#ifndef ZQTDEBUGHANDLER_H
#define ZQTDEBUGHANDLER_H

/*******************************************************************************
** 此类用于将Qt的调试信息作为消息发送出去
**
**
*******************************************************************************/

#include <QObject>
#include <QSharedPointer>
#include <QMutex>
#include "ZFCommonHeader.h"

ZFLIB_BEGIN_NAMESPACE

class ZFLIB_API ZQtDebugHandler : public QObject
{
    Q_OBJECT
public:
    ~ZQtDebugHandler();

    static ZQtDebugHandler * instance();
    static void destroyInstance();

    // 接管所有Qt Debug消息，构造类时会自动调用
    void handle();

    // 放弃对Qt Debug消息的接管
    void release();

signals:
    void message(QtMsgType type, QString msg);

private:
    ZQtDebugHandler(QObject *parent = Q_NULLPTR);

    static QSharedPointer<ZQtDebugHandler> m_instance;
    static QMutex m_instance_mutex;
};

ZFLIB_END_NAMESPACE

#endif // ZQTDEBUGHANDLER_H
